package Sequence;

import java.util.ArrayList;
import java.util.List;

public class Test0491 {
    public static void main(String[] args) {
        new Solution0491_1().findSubsequences(new int[]{4,6,7,7});
    }
}


class Solution0491_1 {
    List<List<Integer>> ans=new ArrayList<>();
    public List<List<Integer>> findSubsequences(int[] nums) {
        ArrayList<Integer> list = new ArrayList<>(nums.length);
        backtrack(nums, 0, list);
        return ans;
    }

    public void backtrack(int[] nums,int index, List<Integer> list) {
        if (list.size()>1) ans.add(new ArrayList<>(list));

        int pre = !list.isEmpty() ? list.get(list.size() - 1):Integer.MIN_VALUE;

        boolean[] record=new boolean[201];
        for (;index<nums.length;index++) {
            int now = nums[index];
            if (!record[now+100]&&now >= pre) {
                record[now+100]=true;
                list.add(now);
                backtrack(nums,index+1,list);
                list.remove(list.size()-1);
            }
        }
    }
}